package com.xiaodeng.xdblogspringboot.mapper;

import com.xiaodeng.xdblogspringboot.pojo.Admin;
import com.xiaodeng.xdblogspringboot.pojo.Article;
import com.xiaodeng.xdblogspringboot.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AdminMapper {
    // 管理员注册
    @Insert("insert into admin(username,password,email,create_time,update_time) values (#{username},#{password},#{email},now(),now())")
    void add(@Param("username")String username, @Param("password")String password, @Param("email") String email);
    //用户名查询用户
    @Select("select * from admin where username = #{username}")
    Admin findByUserName(String username);
    //删除用户
    @Delete("delete from admin where id = #{id}")
    void delete(Integer id);
    //更新用户信息
    @Update("update admin set nickname=#{nickname},email=#{email},update_time=now() where id=#{id}")
    void update(Admin admin);
    //更新用户密码
    @Update("update admin set password=#{md5String},update_time=now() where id =#{id}")
    void updatePwd(@Param("md5String") String md5String,@Param("id") Integer id);
    //更新用户头像
    @Update("update admin set user_pic=#{avatarUrl},update_time=now() where id =#{id}")
    void updateAvatar(@Param("avatarUrl")String avatarUrl,@Param("id") Integer id);
    //   **获取用户列表**
    List<User> userList(@Param("username") String username, @Param("email") String email);
    //  **创建用户**
    @Insert("insert into user(username,password,nickname,user_pic,create_time,update_time) values (#{username},#{password},#{nickname},#{userPic},now(),now())")
    void addUser(User user);
    //  **更新用户信息**
    @Update("update user set username = #{username}, nickname=#{nickname},user_pic=#{userPic}, update_time=now() where id=#{id}")
    void updateUser(User user);
    //重置用户密码
    @Update("update user set password=#{md5String},update_time=now() where id =#{id}")
    void resetPwd(@Param("md5String")String md5String,@Param("id") Integer id);



}
